package com.rpj.stauy.controller;

import com.rpj.stauy.service.MyHighAiService;
import dev.langchain4j.data.message.UserMessage;
import dev.langchain4j.model.chat.ChatModel;
import dev.langchain4j.model.chat.response.ChatResponse;
import dev.langchain4j.model.output.TokenUsage;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("ai")
public class AiController {

    @Resource(name = "qwen")
    private ChatModel chatModelQwen;
    @Resource(name = "deepseek")
    private ChatModel chatModelDeepseek;
    @Resource(name = "aiService")
    private MyHighAiService myHighAiService;


    //http://localhost:9092/ai/low
    @GetMapping("low")
    public String aiLow(@RequestParam(value = "prompt",defaultValue = "你是谁") String prompt){

        ChatResponse chatResponse = chatModelQwen.chat(UserMessage.from(prompt));
        String text = chatResponse.aiMessage().text();
        System.out.println("返回结果：" +text);
        TokenUsage tokenUsage = chatResponse.tokenUsage();
        System.out.println("本次调用消耗token："+ tokenUsage);
        return text+"\t"+ tokenUsage;

    }

    //http://localhost:9092/ai/deepseek
    @GetMapping("deepseek")
    public String aiLowDeepseek(@RequestParam(value = "prompt",defaultValue = "你是谁") String prompt){

        return chatModelDeepseek.chat(prompt);

    }
    //http://localhost:9092/ai/high
    @GetMapping("high")
    public String aiHigh(@RequestParam(value = "prompt",defaultValue = "你是谁") String prompt){
        return myHighAiService.chat(prompt);
    }

}
